/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ca.trader.enterprisebeans;

import ca.trader.except.UUIDDoesNotExistException;
import ca.trader.except.UUIDExistsException;
import ca.trader.except.UserAlreadyExistsException;
import ca.trader.except.UserDoesNotExistException;
import ca.trader.except.UserNotAuthenticatedException;
import ca.trader.user.User;
import ca.trader.user.UserActivationDesc;
import ca.trader.user.UserLoginHistoryRecord;
import javax.ejb.Local;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * The Business interface for the UserBean to be used locally.
 * @author Ahsan
 */
@Local
public interface UserBeanLocal
{	 
	 /**
	  * Get a user with a given email address.
	  * @param email the email address
	  * @return User with the given email address.
	  * @throws UserDoesNotExistException 
	  */
	 User getUserWithEmail(final String email) throws UserDoesNotExistException;

	 /**
	  * Find a user with a given email address.
	  * @param email the email address
	  * @return User with the given email address.  If no user exists with the given email address, null is returned.
	  */
	 User findUserWithEmail(final String email);

	  /* Get a user with the given ID
	  * @param id the user id
	  * @return User with the given id
	  * @throws UserDoesNotExistException 
	  */
	 User getUserWithID(final Integer userID) throws UserDoesNotExistException;

	  /**
	  * Get a user with a given id
	  * @param id the user id
	  * @return User with the given id.  If no user exists with the given id, null is returned.
	  */
	 User findUserWithID(final Integer id);

	 /**	  * 
	  * inserts a user entity bean into the database.
	  * @param user the user to insert
	  * @throws UserAlreadyExistsException 
	  */
	 void saveUser(final User user) throws UserAlreadyExistsException;

	 /**
	  * Inserts a User and UserActivationDesc entity bean into the database
	  * @param desc the user activation object. 
	  * @throws UserAlreadyExistsException 
	  */
	 void saveUserWithActivationDesc(final UserActivationDesc desc) throws UserAlreadyExistsException;

	 /** Finds a user login history record with the given UUID
	  * @param UUID the UUID to look up
	  * @return  the UserLoginHistoryRecord with the given UUID.  Returns null if no UserLoginHistoryRecord exists with the given UUID.
	  */
	 UserLoginHistoryRecord findUserLoginHistoryRecord(String UUID);
	 
	 /**
	  * Insert a UserLoginHistoryRecord entity into the DB
	  * Throw
	  * @param loginRecord the UserLoginHistoryRecord to insert
	  * @throws UUIDExistsException
	  */
	 void insertUserLoginHistoryRecord(UserLoginHistoryRecord loginRecord) throws UUIDExistsException;
	 
	 /**
	  * deletes a UserLoginHistoryRecord with the given UUID
	  * @param UUID the uuid of the UserLoginHistoryRecord to delete
	  * @throws UUIDDoesNotExistException
	  */
	 void deleteUserLoginHistoryRecord(String UUID) throws UUIDDoesNotExistException;

	 /**
	  * "Remembers" a user
	  * @param response the HttpServletResponse object.  User for setting the cookie
	  * @param user the user to "remember"
	  */
	 void rememberUser(HttpServletResponse response, User user);
	 
	 /**
	  * Gets the authenticated user associated with the given HttpSession.  
	  * @param session The HttpSession to search the user in
	  * @return the authenticated user.  
	  * @throws UserDoesNotExistException 
	  * @throws UserNotAuthenticatedException
	  */
	 User getAuthenticatedUser(HttpSession session) throws UserDoesNotExistException, UserNotAuthenticatedException;

	 /**
	  * "Forgets" a user which has already been "remembered".  
	  * @param request the HttpServletRequest object
	  * @param response  the HttpServletResponse object
	  */
	 void forgetUser(HttpServletRequest request, HttpServletResponse response);

}
